<?php

namespace App\Models\Vuls;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;
use Illuminate\Database\Eloquent\SoftDeletes;

class Vuls extends Model
{
    //使用软删除
    use SoftDeletes;
    //关联表
    protected  $table = 'vuls';
    //要填充的字段
    protected $fillable = ['title','description','user_id','app_id','category_id','level_id','content','reward'
        ,'credit','status','is_delete','delete_at','vuls_number','form_url','url_parms','payload'
    ];
    //软删除自动维护字段,不为空时此条数据不显示
    protected $dates = ['deleted_at'];
    /**
     * @var array  声明漏洞状态--原始即漏洞后台
     */
    public static $vulsStatus = [
        '0' => ['待审核'],
        '1' => ['已审核'],
        '2' => ['待确认'],
        '3' => ['待修复'],
        '4' => ['已修复'],
        '5' => ['已解决'],
        '6' => ['已关闭'],
        '7' => ['申诉中'],
        '8' => ['已忽略'],
/*        '9' => ['全部'],
        '10' => ['已拒绝'],*/
        '11' => ['无影响'],
    ];
    /**
     * @var array  声明漏洞状态--前台对应的状态
     */
    public static $vulsStatusMerge = [
        '0' => ['name' => '待审核', 'code' => '0'],
        '1' => ['name' => '审核中', 'code' => '1, 2, 7'],
        '2' => ['name' => '已确认', 'code' => '3, 4'],
        '3' => ['name' => '已修复', 'code' => '5, 6'],
        '4' => ['name' => '已忽略', 'code' => '8, 11'],
    ];
    /**
     * validate 表单数据验证
     *
     * @param $data
     * @return bool
     */
    public  static function validate($data){
        return  Validator::make($data, [
            'title'=>'required',
            'category_id'=>'required|integer',
            'level_id'=>'required|integer',
            'from_url'=>'required',
            'payload'=>'required|max:1000',
            'contents'=>'required',
            'captcha' => 'required|captcha',
        ],[
                'title.required' => '请填写漏洞名称！',
                'category_id.required' => '请选择漏洞类型！',
                'category_id.integer' => '请选择漏洞类型！',
                'level_id.required' => '请选择漏洞自评等级！',
                'level_id.integer' => '请选择漏洞自评等级！',
                'from_url.required' => '请填写漏洞url来源！',
                'payload.required' => '请填写漏洞负载！',
                'content.required' => '请填写漏洞内容！',
                'captcha.required' => '请填写验证码！',
                'captcha.captcha' => '验证码不正确！',
            ]
        );
    }
}
